package com.example.katalk_nari;

import java.util.ArrayList;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ListView;

public class MainActivity extends Activity {
	
	EditText etMessage;
	CheckBox cbIsSend;
	ChatItemAdapter adapter;
	
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ListView listview = (ListView)findViewById(R.id.lvChat);
        
        ArrayList<ChatItemData> datas = new ArrayList<ChatItemData>();
        adapter = new ChatItemAdapter(this, datas);
        listview.setAdapter(adapter);
        
        etMessage = (EditText)findViewById(R.id.etInputMessage);
        cbIsSend = (CheckBox)findViewById(R.id.cbIsSend);

        Button btnAddItem  = (Button)findViewById(R.id.btnAddData);
        btnAddItem.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				String msg = etMessage.getText().toString();
				if (msg.length()<1)
					return;
				if (cbIsSend.isChecked()){
					adapter.add(new SendMessageData(msg));
				}else{
					adapter.add(new ReciveMessageData(msg,"YOU"));
				}
				etMessage.setText("");
			}
		});
        Button btnAddDate  = (Button)findViewById(R.id.btnAddDateBar);
        btnAddDate.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				adapter.add(new TimeBarData());				
			}
		});
        
    }

}